from web.scraper.ocr.line1.main import AllAiLine2
from web.api.result import result
line1 = AllAiLine2()




# 开始对话
def start_dialogue(request):
    dialogue_id = request.POST.get("dialogue_id")
    img_file = request.FILES.get("img_file") # 二进制图片
    img_size = img_file.size
    upload_image_response = line1.upload_image.upload_image(img_file, img_size)['response']['resourceUrl']
    response = line1.identify_image_content(upload_image_response, dialogue_id=dialogue_id)
    # 获取识别结果
    response = response.split("#IMAGETEXTSTART")[1].split("#IMAGETEXTEND")[0]
    return result(200, "success", response)


# 创建模型id
def create_dialogue(request):
    model_name = request.GET.get("model_name")
    response = line1.create_dialogue()
    return result(200, "success", {
        "model_id": response['id'],
        "model_name": model_name
    })

